/**
 * <p>
 * 处理cookie的帮助类
 * </p>
 * @class
 * @param ctx 标示变量
 */

function cookie(ctx) {
  this.context = ctx;
  if (document.cookie.length) {
    this.cookies = ' ' + document.cookie;
  };
};

/**
 * <p>
 * 设置cookie的方法。
 * </p>
 * @param key cookie的主键
 * @param value cookie的值
 */
cookie.prototype.setCookie = function (key, value) {
	var uKey = this.context + key;
	document.cookie = uKey + "=" + escape(value);
};

/**
 * <p>
 * 获得cookie内容的方法
 * </p>
 * @param key cookie的主键
 * @return {string} cookie的值
 */
cookie.prototype.getCookie = function (key) {
	var uKey = this.context + key;
	if (this.cookies) {
		var start = this.cookies.indexOf(' ' + uKey + '=');
		if (start == -1) { return null; };
		var end = this.cookies.indexOf(";", start);
		if (end == -1) { end = this.cookies.length; };
		end -= start;
		var cookie = this.cookies.substr(start,end);
		var firstIdx = cookie.indexOf('=') + 1;
		var lastIdx = cookie.length - cookie.indexOf('=') + 1;
		var tous = cookie.substr( firstIdx, lastIdx );
		return unescape(tous);
	} else { 
		return null; 
	};
};